import 'package:flutter/material.dart';

enum Option{
  A, B, C
}

class SimpleDialogDemo extends StatefulWidget {
  const SimpleDialogDemo({super.key});

  @override
  State<SimpleDialogDemo> createState() => _SimpleDialogDemoState();
}

class _SimpleDialogDemoState extends State<SimpleDialogDemo> {
  String _choice = 'Nothing';

  _openSimpleDialog() async{

    final option = await showDialog(
        context: context,
        builder: (BuildContext buildContext) {
          return SimpleDialog(
            title: Text('SimpleDialog'),
            children: [
              SimpleDialogOption(
                child: Text('option A'),
                onPressed: (){
                  Navigator.pop(context, Option.A);
                },
              ),
              SimpleDialogOption(
                child: Text('option B'),
                onPressed: (){
                  Navigator.pop(context, Option.B);
                },
              ),
              SimpleDialogOption(
                child: Text('option C'),
                onPressed: (){
                  Navigator.pop(context, Option.C);
                },
              )
            ],
          );
        });
  
    switch (option){
      case Option.A:
        setState(() {
          _choice = 'A';
        });
      break;
      case Option.B:
        setState(() {
          _choice = 'B';
        });
      break;
      case Option.C:
        setState(() {
          _choice = 'C';
        });
      break;
      default:break;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('SimpleDialogDemo'),
          elevation: 0.0,
        ),
        body: Container(
          padding: EdgeInsets.all(16.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('select:$_choice')
                ],
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.format_list_numbered),
          onPressed: _openSimpleDialog,
        ));
  }
}
